<?php
function fnMstJenis() {
    $results = mysql_query("SELECT	
                                id,
                                keterangan
                            FROM
                                mst_jenis
                            ORDER BY
                                keterangan ASC");
    return $results;
}

function fnInsertBarang($vIDKategori,$vNama,$vKeterangan,$vUkuran,$vWarna,$vTglMasuk,$vHarga,$vJumlah,$vIDSupplier) {
    $result = mysql_query("INSERT INTO `mst_barang`
                           (id_jenis,nama,keterangan,ukuran,warna,tgl_masuk,harga,jumlah,id_supplier)
                           VALUES
                           ($vIDKategori,'$vNama','$vKeterangan','$vUkuran','$vWarna','$vTglMasuk',$vHarga,$vJumlah,$vIDSupplier)");
    return $result;
}

function fnUpdateBarang($vIDBarang,$vIDKategori,$vNama,$vKeterangan,$vUkuran,$vWarna,$vTglMasuk,$vHarga,$vJumlah,$vIDSupplier) {
    $result = mysql_query("UPDATE `mst_barang` SET 
                            id_jenis = $vIDKategori,
                            nama = '$vNama',
                            keterangan = '$vKeterangan',
                            ukuran = '$vUkuran',
                            warna = '$vWarna',
                            tgl_masuk = '$vTglMasuk',
                            harga = $vHarga,
                            jumlah = $vJumlah,
                            id_supplier = $vIDSupplier
                           WHERE id = $vIDBarang");
    return $result;
}

function fnDeleteBarang($vIDBarang) {
    $result = mysql_query("DELETE FROM `mst_barang` 
                           WHERE id = $vIDBarang");
    return $result;
}

function fnAllBrg() {
//    $results = mysql_query("select c.* from (
//                            select @rownum:=@rownum+1 as rownum, a.*
//                            from vbrgjnssup a, (select @rownum:=0) b
//                            ) c");
    $results = mysql_query("select d.* from (
                                select @rownum:=@rownum+1 as rownum, b.* from (
                                    select * from vbrgjnssup a order by a.tglmasuk DESC
                                ) b, (select @rownum:=0) c
                            ) d");
    return $results;
}

function fnAllBrgByRange($startNum, $endNum) {
//    $results = mysql_query("select c.* from (
//                                select @rownum:=@rownum+1 as rownum, a.*
//                                from vbrgjnssup a, (select @rownum:=0) b
//                            ) c where 1=1
//                            and c.rownum between ".$startNum." and ".$endNum);
    $results = mysql_query("select c.* from (
                                select @rownum:=@rownum+1 as rownum, d.* from (
                                    select * from vbrgjnssup a order by a.tglmasuk DESC
                                ) d, (select @rownum:=0) b
                            ) c where 1=1
                            and c.rownum between ".$startNum." and ".$endNum);
    return $results;
}

function fnBrgByKategori($kategori) {
//    $results = mysql_query("select @rownum:=@rownum+1 as rownum, c.* from (
//                                select a.* from vbrgjnssup a
//                            ) c, (select @rownum:=0) b 
//                            where 1=1
//                            and c.kategori_id = ".$kategori);
    $results = mysql_query("select @rownum:=@rownum+1 as rownum, c.* from (
                                select a.* from vbrgjnssup a order by a.tglmasuk DESC
                            ) c, (select @rownum:=0) b 
                            where 1=1
                            and c.kategori_id = ".$kategori);
    return $results;
}

function fnBrgByKategoriAndRange($kategori, $startNum, $endNum) {
    $results = mysql_query("select * from (
                            select @rownum:=@rownum+1 as rownum, c.* from (
                            select a.* from vbrgjnssup a order by a.tglmasuk DESC
                            ) c, (select @rownum:=0) b 
                            where c.kategori_id = ".$kategori." 
                            ) d
                            where d.rownum between ".$startNum." and ".$endNum);
    return $results;
}

function fnBrgByRownum($rownum) {
    $results = mysql_query("select c.* from (
                            select @rownum:=@rownum+1 as rownum, a.*
                            from vbrgjnssup a, (select @rownum:=0) b
                            ) c where 1=1
                            and c.rownum = ".$rownum);
    return $results;
}

function fnBrgByID($idBarang) {
    $results = mysql_query("select c.* from (
                            select @rownum:=@rownum+1 as rownum, a.*
                            from vbrgjnssup a, (select @rownum:=0) b
                            ) c where 1=1
                            and c.id = ".$idBarang);
    return $results;
}

?>
